home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
CUGUK
/
APPLICAT
/
C034.ZIP
/
DBQCRE.C
< prev
next >
Wrap
Text File
|
2010-11-01
|
3KB
|
131 lines
/* SDB - relation creation routines */
#include "bdscio.h"
#include "dbqdefs.h"
struct relation *db_rcreate(rname)
char *rname;
{
struct relation *rptr;
if ((rptr = alloc(RELSIZE)) == NULL)
{ RETERR(INSMEM) }
strncpy(rptr->rl_name,rname,RNSIZE);
rptr->rl_tcnt = 0;
rptr->rl_tmax = 0;
rptr->rl_data = 512;
rptr->rl_size = 1;
rptr->rl_header.hd_attrs[0].at_name[0] = 0;
return (rptr);
}
int db_rcheader(rptr)
struct relation *rptr;
{
char rname[RNSIZE+1],filename[RNSIZE+13];
db_cvbytes(rptr->rl_tcnt,rptr->rl_header.hd_tcnt);
db_cvbytes(rptr->rl_tmax,rptr->rl_header.hd_tmax);
db_cvbytes(rptr->rl_data,rptr->rl_header.hd_data);
db_cvbytes(rptr->rl_size,rptr->rl_header.hd_size);
strncpy(rname,rptr->rl_name,RNSIZE);
rname[RNSIZE] = 0;
sprintf(filename,"%s.dbq",rname);
if ((ccreat(rptr->rl_fd,filename)) == -1) {
free(rptr);
RETERR(RELCRE)
}
if (cwrite(rptr->rl_fd,&rptr->rl_header,512) != 512) {
cclose(rptr->rl_fd);
free(rptr);
RETERR(BADHDR)
}
return (TRUE);
}
int db_rctuples(rptr,tcnt)
struct relation *rptr;
unsigned tcnt;
{
unsigned i;
char *tbuf;
rptr->rl_tmax = tcnt;
if ((tbuf = alloc(RELSIZE)) == NULL)
{ RETERR(INSMEM) }
for (i = 0; i < tcnt; i++)
if (cwrite(rptr->rl_fd,tbuf,rptr->rl_size) != rptr->rl_size) {
free(tbuf);
RETERR(INSBLK)
}
free(tbuf);
return(TRUE);
}
int db_rcdone(rptr)
struct relation *rptr;
{
db_cvbytes(rptr->rl_tcnt,rptr->rl_header.hd_tcnt);
db_cvbytes(rptr->rl_tmax,rptr->rl_header.hd_tmax);
#ifdef DEBUG
printf("rcdone - %d, %d, %d\n",rptr->rl_tmax,
rptr->rl_header.hd_tmax[0],
rptr->rl_header.hd_tmax[1]);
#endif
cseek(rptr->rl_fd,0,0);
if (cwrite(rptr->rl_fd,&rptr->rl_header,512) != 512) {
cclose(rptr->rl_fd);
free(rptr);
RETERR(BADHDR)
}
cclose(rptr->rl_fd);
free(rptr);
return(TRUE);
}
int db_rcattr(rptr,aname,type,size,scale)
struct relation *rptr;
char *aname;
int type,size,scale;
{
int i;
for (i = 0; i < NATTRS; i++)
if (rptr->rl_header.hd_attrs[i].at_name[0] == 0)
break;
else if (db_sncmp(aname,rptr->rl_header.hd_attrs[i].at_name,ANSIZE) == 0)
{ RETERR(DUPATT) }
if (i == NATTRS)
{ RETERR(MAXATT) }
strncpy(rptr->rl_header.hd_attrs[i].at_name,aname,ANSIZE);
rptr->rl_header.hd_attrs[i].at_type = type;
rptr->rl_header.hd_attrs[i].at_size = size;
rptr->rl_header.hd_attrs[i].at_scale = scale;
if (++i != NATTRS)
rptr->rl_header.hd_attrs[i].at_name[0] = 0;
rptr->rl_size += size;
return(TRUE);
}
cale;
if (++i != NATTRS)
rptr->rl_header.hd_attrs[i].at_name[0] = 0;
rptr-